package com.qf.service;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.entity.dto.Area;
import com.qf.mapper.AreaMapper;
import com.qf.service.redis.RedisService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AreaService extends ServiceImpl<AreaMapper, Area> {
    @Resource
    RedisService redisService;

    @Transactional
    public List<Area> queryArea(String cityId) {
        List<Area> list3 = null;
        String s = (String) redisService.hget("area", cityId);
        if (s != null && !s.equals("")) {
            list3 = JSONObject.parseArray(s, Area.class);
            return list3;
        }
        list3 = this.baseMapper.queryArea(cityId);
        redisService.hset("area", cityId, JSONObject.toJSONString(list3));
        return list3;
    }
}
